package net.azure.app.model;

import static net.azure.app.GlobalConstants.STORY_DETAILS_FIELD_COUNT;
import static net.azure.app.GlobalConstants.RISK_FIELD_COUNT;
import static net.azure.app.GlobalConstants.ESTIMATE_FIELD_COUNT;

import java.util.List;
import java.util.LinkedList;

/**
 * Created by IntelliJ IDEA.
 * User: Venkatraman Kandaswamy
 * Date: 12-Jun-2008
 * Time: 06:40:15
 */
public class Story implements IModel{
    int MSL;
    StoryDetails storyDetails;
    Risk risk;
    Estimate estimate;

    public Story(int MSL, StoryDetails storyDetails, Risk risk, Estimate estimate) {
        this.MSL = MSL;
        this.storyDetails = storyDetails;
        this.risk = risk;
        this.estimate = estimate;
    }

    public int getMSL() {
        return MSL;
    }

    public void setMSL(int MSL) {
        this.MSL = MSL;
    }

    public StoryDetails getStoryDetails() {
        return storyDetails;
    }

    public void setStoryDetails(StoryDetails storyDetails) {
        this.storyDetails = storyDetails;
    }

    public Risk getRisk() {
        return risk;
    }

    public void setRisk(Risk risk) {
        this.risk = risk;
    }

    public Estimate getEstimate() {
        return estimate;
    }

    public void setEstimate(Estimate estimate) {
        this.estimate = estimate;
    }

    @Override
    public Object field(int position){
        if(position == 0 ) return MSL;
        position -= 1;

        if(position < STORY_DETAILS_FIELD_COUNT) return storyDetails.field(position);
        position -= STORY_DETAILS_FIELD_COUNT;

        if(position < RISK_FIELD_COUNT) return risk.field(position);
        position -= RISK_FIELD_COUNT;

        if(position < ESTIMATE_FIELD_COUNT) return estimate.field(position);

        return null;
    }

    @Override
    public List<String> header(){
        List<String> headersList = new LinkedList<String>();
        headersList.add("MSL");
        headersList.addAll(storyDetails.header());
        headersList.addAll(risk.header());
        headersList.addAll(estimate.header());
        return headersList;
    }
}
